﻿using DoNetDrive.Core.Connector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DoNetDrive.AspWebSocke.WebSocketServer
{
    public static class WebSocketServerConnectorStatus
    {
        public static WebSocketServerConnectorStatus_Closed Closed { get; set; }
        public static WebSocketServerConnectorStatus_Connecting Connecting { get; set; }
        public static WebSocketServerConnectorStatus_Connected Connected { get; set; }
        static WebSocketServerConnectorStatus()
        {
            Closed = new();
            Connecting = new();
            Connected = new();
        }
    }


    public class WebSocketServerConnectorStatus_Closed : INConnectorStatus
    {
        public void CheckStatus(INConnector connector)
        {
            if (!connector.CheckIsInvalid())
            {
                var Client = connector as WebSocketServerConnector;
                connector.ConnectAsync().ContinueWith(Client.ConnectingNext);
            }
        }

        public string Status()
        {
            return "Closed";
        }
    }

    public class WebSocketServerConnectorStatus_Connecting : INConnectorStatus
    {
        public void CheckStatus(INConnector connector)
        {
            var Client = connector as WebSocketServerConnector;
            Client.CheckConnectorTimeout();
        }

        public string Status()
        {
            return "Connecting";
        }
    }

    public class WebSocketServerConnectorStatus_Connected : INConnectorStatus
    {
        public void CheckStatus(INConnector connector)
        {
            var Client = connector as WebSocketServerConnector;
            Client.CheckConnectedStatus();
        }

        public string Status()
        {
            return "Connected";
        }
    }
}
